package com.dosen.api.thought.common.enums;

import lombok.Getter;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @version V1.0
 * @author: guangcheng
 * @date: 2023/2/4 23:21
 * @description: 思想内容类型：文件，音频，视频，字符串等
 */
@Getter
public enum ThoughtStorageMediaType {
    STRING(1, "字符串", "string"),
    TEXT(2, "文本", "text"),
    AUDIO(3, "音频", "audio"),
    VIDEO(4, "视频", "video"),
    GIT(5, "仓库", "git"),
    ;


    private int index;
    private String cnName;
    private String enName;

    ThoughtStorageMediaType(int index, String cnName, String enName) {
        this.index = index;
        this.cnName = cnName;
        this.enName = enName;
    }

    /**
     * @param index
     * @return
     */
    public static ThoughtStorageMediaType getInstance(Integer index) {
        List<ThoughtStorageMediaType> collect = Arrays.stream(values()).filter(item -> item.index - index == 0).collect(Collectors.toList());
        return !CollectionUtils.isEmpty(collect) ? collect.get(0) : null;
    }

    /**
     *
     * @param enName
     * @return
     */
    public static ThoughtStorageMediaType getInstance(String enName) {
        List<ThoughtStorageMediaType> collect = Arrays.stream(values()).filter(item -> item.enName.equals(enName)).collect(Collectors.toList());
        return !CollectionUtils.isEmpty(collect) ? collect.get(0) : null;
    }

}
